package com.ruoyi.web.controller.energy;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.energy.domain.EnergyConsumption;
import com.ruoyi.energy.service.IEnergyConsumptionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 能耗信息Controller
 * 
 * @author ruoyi
 * @date 2021-07-08
 */
@Api("能耗管理")
@RestController
@RequestMapping("/energy/consumption")
public class EnergyConsumptionController extends BaseController
{
    @Autowired
    private IEnergyConsumptionService energyConsumptionService;

    /**
     * 查询能耗信息列表
     */
    @ApiOperation("查询能耗列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('energy:consumption:list')")
    @GetMapping("/list")
    public TableDataInfo list(EnergyConsumption energyConsumption)
    {
        startPage();
        List<EnergyConsumption> list = energyConsumptionService.selectEnergyConsumptionList(energyConsumption);
        return getDataTable(list);
    }

    /**
     * 导出能耗信息列表
     */
    @ApiOperation("导出能耗列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('energy:consumption:export')")
    @Log(title = "能耗信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EnergyConsumption energyConsumption)
    {
        List<EnergyConsumption> list = energyConsumptionService.selectEnergyConsumptionList(energyConsumption);
        ExcelUtil<EnergyConsumption> util = new ExcelUtil<EnergyConsumption>(EnergyConsumption.class);
        return util.exportExcel(list, "能耗信息数据");
    }

    /**
     * 获取能耗信息详细信息
     */
    @ApiOperation("获取能耗详细信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('energy:consumption:query')")
    @GetMapping(value = "/{energyConsumptionId}")
    public AjaxResult getInfo(@PathVariable("energyConsumptionId") Long energyConsumptionId)
    {
        return AjaxResult.success(energyConsumptionService.selectEnergyConsumptionById(energyConsumptionId));
    }

    /**
     * 新增能耗信息
     */
    @ApiOperation("新增能耗信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('energy:consumption:add')")
    @Log(title = "能耗信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EnergyConsumption energyConsumption)
    {
        return toAjax(energyConsumptionService.insertEnergyConsumption(energyConsumption));
    }

    /**
     * 修改能耗信息
     */
    @ApiOperation("修改能耗信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('energy:consumption:edit')")
    @Log(title = "能耗信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EnergyConsumption energyConsumption)
    {
        return toAjax(energyConsumptionService.updateEnergyConsumption(energyConsumption));
    }

    /**
     * 删除能耗信息
     */
    @ApiOperation("删除能耗信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('energy:consumption:remove')")
    @Log(title = "能耗信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{energyConsumptionIds}")
    public AjaxResult remove(@PathVariable Long[] energyConsumptionIds)
    {
        return toAjax(energyConsumptionService.deleteEnergyConsumptionByIds(energyConsumptionIds));
    }
}
